<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>新增定时任务</title>
    <link rel="icon" th:href="@{/img/icon.ico}">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/layuimini/css/public.css}" media="all">
    <style>
        .layui-form-item .layui-input-company {
            width: auto;padding-right: 10px;line-height: 38px;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <form class="layui-form" action="" lay-filter="formDemo">
            <div class="layui-form layuimini-form">
                <div class="layui-form-item">
                    <label class="layui-form-label required">任务类名</label>
                    <div class="layui-input-block">
                        <input type="text" name="className" lay-verify="required|classname" lay-reqtext="请输入任务类名" placeholder="请输入" class="layui-input">
                        <tip>任务类名应为定时任务类的文件路径，请填写全英文</tip>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">cron表达式</label>
                    <div class="layui-input-block">
                        <input type="text" name="cronExpression" lay-verify="required" lay-reqtext="请输入cron表达式" placeholder="请输入" class="layui-input" value="* * * * * ?">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">参数</label>
                    <div class="layui-input-block">
                        <textarea name="param" placeholder="请输入" class="layui-textarea" style="resize: none"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">描述</label>
                    <div class="layui-input-block">
                        <textarea name="descript" placeholder="请输入" class="layui-textarea" style="resize: none"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">任务状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="quartzStatus" th:each="item : ${status}" th:value="${item.code}" th:title="${item.name}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit lay-filter="saveBtn" shiro:hasPermission="sys:quartz:add"> 保存 </button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript" th:src="@{/layui/layui.js}"></script>

<script type="text/javascript" th:inline="javascript">

    layui.use(['form','notice'], function () {
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer,
            notice = layui.notice;

        var ctxPath = /*[[@{/}]]*/;
        var baseUrl = ctxPath + 'sys/sys-quartz/';

        form.verify({
            //我们既支持上述函数式的方式，也支持下述数组的形式
            //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
            classname: [
                /^[a-zA-Z]+(\.([a-zA-Z])+)+$/
                ,'请填写正确的任务类名'
            ]
        });

        form.val("formDemo", {
            "quartzStatus": 0
        });

        // 监听提交
        form.on('submit(saveBtn)', function (res) {
            var data = res.field;
            var index = layer.load();
            $.ajax({
                url: baseUrl + 'add',
                type: 'post',
                dataType: 'json',
                data: JSON.stringify(data),
                contentType:"application/json",
                success: function (res) {
                    layer.close(index);
                    if (200 == res.code) {
                        notice.success(res.msg);
                        setTimeout(function () {
                            var windowIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(windowIndex);
                        },1500)
                    }
                    else {
                        notice.warning(res.msg);
                    }
                },
                error: function (res) {
                    layer.close(index);
                    notice.error("服务器异常！");
                }
            });
            return false;
        });
    });
</script>
</body>
</html>